package model;

/**
 * The MaterialListCached class is a State with a cached MaterialList.
 * 
 * @author hfi411pi
 *
 */
public class MaterialListCached extends Cached{

	/**
	 * Factory method for creating a MaterialListCached state.
	 * @param master is the ComponentCommon of this state.
	 * @param materials is the cached MaterialList.
	 * @return the created state.
	 */
	public static MaterialListCached create(final ComponentCommon master,final MaterialList materials){
		return new MaterialListCached(master,materials);
	}
	
	/**
	 * Constructor of MaterialListCached.
	 * @param master is the ComponentCommon of this state.
	 * @param materials is the cached MaterialList.
	 */
	private MaterialListCached(final ComponentCommon master, final MaterialList materials) {
		super(master, materials);
	}
	@Override
	public MaterialList getMaterialList() {
		return this.getMaterials();
	}
	@Override
	public int getOverallPrice() {
		final int overallPrice = this.getMaster().calculateNewOverallPrice();
		this.getMaster().setState(MaterialListPriceCached.create(this.getMaster(), this.getMaterials(), overallPrice));
		return overallPrice;
	}
	@Override
	protected void handlePriceChangedEvent(final PriceChangedEvent priceChangedEvent) {
		
	}
	@Override
	protected void handleStructureChangedEvent(
			final StructureChangedEvent structureChangedEvent) {
		this.getMaster().setState(NotCached.create(this.getMaster()));
	}

	@Override
	public String toString(){
		return PartsListConstants.materialListCached;
	}
}
